<?php
    require_once("condb.php");
    require_once("functions.php");
    
    $output = array();
    $info = isset($_GET["info"]) ? $_GET["info"] : "";
    if(!empty($info)){
        $info = urldecode(base64_decode($info));
        parse_str($info, $request);    
        
        $token = isset($request["token"]) ? cleanQuery($request["token"]) : "";
        if($token=="TAoViEC@)!#2012"){
            
            $data = array();
            $data["appId"] = isset($request["appId"]) ? intval($request["appId"]) : 0;            
            
            if(!empty($data["appId"])){
                
                $active = getLastestActive($data);
                if(empty($active)){
                    
                    /* Chưa kích hoạt lần nào */
                    $output["status"] = 1;                    
                    $output["msg"] = "1";                    
                    
                } else {
                    $active["level"]++;
                    $output["status"] = 1;                    
                    $output["msg"] = $active["level"];
                }    
            } else {
                $output["status"] = 4;
                $output["msg"] = "Invalid Request";    
            }
            
            
        } else {
            $output["status"] = 3;
            $output["msg"] = "Invalid Request";    
        }
    } else {
        $output["status"] = 2;
        $output["msg"] = "Invalid Request";
    }

    echo json_encode($output);  
?>